package it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners;

import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Widget;


abstract public class FResizePoller {
    Widget polledWidget;
    Timer timer;
    int prevW = 0;
    int prevH = 0;

    public FResizePoller(Widget w) {

        polledWidget = w;


        timer = new Timer() {


            public void run() {
                if (prevW == polledWidget.getOffsetWidth() && prevH == polledWidget.getOffsetHeight())
                    return;

                prevW = polledWidget.getOffsetWidth();
                prevH = polledWidget.getOffsetHeight();
                onResize(polledWidget.getOffsetWidth(), polledWidget.getOffsetHeight());

            }
        };

    }

    public void startPolling(int schedule) {
        timer.scheduleRepeating(schedule);
    }

    public void stopPolling() {
        timer.cancel();
    }

    abstract public void onResize(int w, int h);

}
